package com.qp.basics.admin.controller;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.util.Date;

public class CCSJwtUtil {

    // 私钥
    // private final static String base64Secret =
    // "MDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjY=";
    private String base64Secret;
    // 超时时长 毫秒
    // private final static int expiresSecond = 172800000;
    private int expiresSecond;

    // 解析内容
    public Claims parseJWT(String jsonWebToken) {
        try {
            base64Secret="MDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjY={ccssoft.com}";
            expiresSecond=18000000;
            System.out.println("base64Secret-----" + base64Secret);
            Claims claims = Jwts.parser().setSigningKey(DatatypeConverter.parseBase64Binary(base64Secret)).parseClaimsJws(jsonWebToken).getBody();
            return claims;
        } catch (Exception ex) {
            return null;
        }
    }
    public static void main(String[] args) {
        CCSJwtUtil jwtUtil = new CCSJwtUtil();
        Claims body = jwtUtil.parseJWT("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbk5hbWUiOiJzYSIsInRlbmFudElkIjoiMTIzNDUiLCJleHAiOjE2Mzk5MjI5OTgsIm5iZiI6MTYzOTkwNDk5OH0.wg5FUmILG4EzZZxG5UVEuK7WR5niNoSqeqEPdo7vEoo");
        System.out.println(body);
    }
}
